//
//  MapRouteViewController.m
//  SXH
//
//  Created by 龚啸 on 16/1/21.
//  Copyright © 2016年 lyss. All rights reserved.
//

#import "MapRouteViewController.h"
#import "BasicMapAnnotation.h"
#import "MapTableViewCell.h"
#import "RoadLineEntity.h"
@interface MapRouteViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labelTitle;
@property (weak, nonatomic) IBOutlet UITableView *mpTableView;

@property (nonatomic,assign)NSInteger index;
@end

@implementation MapRouteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _labelTitle.text = _stringTitle;
   
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_arrayTitle count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"MapTableViewCell";
    MapTableViewCell *cell = (MapTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MapTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];

    }
    if ([_stringTitle isEqualToString:@"起点选择"]) {
        [cell.imgView setImage:[UIImage imageNamed:@"收货地址" ]];
        BasicMapAnnotation * annotation = [_arrayTitle objectAtIndex:indexPath.row];
        cell.titleLabel.text =annotation.title;
    }else if ([_stringTitle isEqualToString:@"终点选择"]){
        [cell.imgView setImage:[UIImage imageNamed:@"收货地址" ]];
        BasicMapAnnotation * annotation = [_arrayTitle objectAtIndex:indexPath.row];
        cell.titleLabel.text =annotation.title;
    }else{
        [cell.imgView setImage:[UIImage imageNamed:@"收货地址" ]];
        RoadLineEntity *entity = [_arrayTitle objectAtIndex:indexPath.row];
        cell.titleLabel.text = entity.title;
    }
    
    
    self.index = indexPath.row;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 59;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //当手指离开某行时，就让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (_block) {
         _block(indexPath.row);
    }
    NSLog(@"123");
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)transIndexBlock:(mpBlcok)block
{
    _block = block;
    NSLog(@"blockOk");
}
- (IBAction)back:(id)sender {
     [self dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
